package com.potato.model1.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.potato.model1.R;
import com.potato.model1.bean.CategoryResult;

import java.util.List;

public class HomeSubAdapter extends BaseQuickAdapter<CategoryResult, BaseViewHolder> {

    public HomeSubAdapter( @Nullable List<CategoryResult> data) {
        super(R.layout.item_category, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CategoryResult item) {
        helper.setText(R.id.tv_author, item.who)
                .setText(R.id.tv_content, item.desc)
                .setText(R.id.tv_type, item.source)
                .setText(R.id.tv_date, item.createdAt.split("T")[0]);
        ImageView ivPic = helper.getView(R.id.iv_pic);
        ivPic.setVisibility(View.GONE);
        if (item.images != null && item.images!=null) {
            ivPic.setVisibility(View.VISIBLE);
            Glide.with(mContext).load(item.images.get(0)).into(ivPic);
        }
    }
}
